package se.thoka.twt.client.event;

import com.google.gwt.event.shared.GwtEvent;

public class ListItemClickedEvent<LI> extends GwtEvent<ListItemClickedHandler<LI>> {

	private static Type<ListItemClickedHandler<?>> TYPE = new Type<ListItemClickedHandler<?>>();
	
	private final LI t;
	private final int listIndex;
	private final boolean shiftKeyDown, ctrlKeyDown;

	/**
	 * Creates a new instance of {@link ListItemClickedEvent}
	 * @param t The clicked object
	 * @param listIndex The list index of the clicked object
	 * @param shiftKeyDown Set <code>true</code> if the SHIFT key was down while user clicked
	 * @param ctrlKeyDown Set <code>true</code> of the CTRL key was down while user clicked
	 */
	public ListItemClickedEvent(LI t, int listIndex, boolean shiftKeyDown, boolean ctrlKeyDown) {
		this.t = t;
		this.listIndex = listIndex;
		this.shiftKeyDown = shiftKeyDown;
		this.ctrlKeyDown = ctrlKeyDown;
	}
	
	/**
	 * @return The clicked list item
	 */
	public LI getListItem() {
		return t;
	}
	
	/**
	 * @return The list item index of the clicked item
	 */
	public int getListItemIndex() {
		return listIndex;
	}
	
	/**
	 * @return <code>true</code> if SHIFT key was down while user clicked the event
	 */
	public boolean isShiftKeyDown() {
		return shiftKeyDown;
	}
	
	/**
	 * @return <code>true</code> if CONTROL key was down while user clicked the event
	 */
	public boolean isCtrlKeyDown() {
		return ctrlKeyDown;
	}

	@Override
	protected void dispatch(ListItemClickedHandler<LI> handler) {
		handler.onListItemClicked(this);
	}

	@Override
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Type<ListItemClickedHandler<LI>> getAssociatedType() {
		return (Type) getType();
	}

	public static Type<ListItemClickedHandler<?>> getType() {
		return TYPE;
	}
}
